/**
 * Copyright (c) 2020-2021 浦东大爷 All rights reserved.
 * 机会永远都是留给有准备的人
 */
package com.lagou.service.impl;

import com.lagou.common.ServerResponse;
import com.lagou.mapper.EduMapper;
import com.lagou.service.IEduService;
import com.lagou.vo.ConverterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: gitwo
 * @date: 2021-03-11
 * @description:
 */
@Service
@Transactional  //事务控制
public class EduServiceImpl implements IEduService {

    @Autowired
    private EduMapper eduMapper;

    @Override
    public ServerResponse<Map<String, Object>> getEduData() {

        Map<String, Object> map = new HashMap<>();

        List<ConverterVo> converterVoList = eduMapper.getEdu();

        List<String> namesList = new ArrayList<>();
        List<String> valuesList = new ArrayList<>();

        for (ConverterVo converterVo : converterVoList) {
            namesList.add(converterVo.getName());
            valuesList.add(converterVo.getValue());
        }

        map.put("names", namesList);
        map.put("countNum", valuesList);
        map.put("eduData", converterVoList);

        return ServerResponse.createBySuccessData(map);
    }
}
